<?php

namespace App\Containers\AppSection\Pledge\UI\API\Transformers;

use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Containers\AppSection\Pledge\Models\Movable;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class MovableTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'documents', 'pts_scans', 'sts_scans', 'images'
    ];

    /**
     * @param Movable $t
     * @return array
     */
    public function transform(Movable $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'name' => $t->name,
            'brand_model' => $t->brand_model,
            'year' => $t->year,
            'body' => $t->body,
            'engine_volume' => $t->engine_volume,
            'engine_type' => $t->engine_type,
            'chassis' => $t->chassis,
            'body_color' => $t->body_color,
            'engine_model_number' => $t->engine_model_number,
            'engine_power' => $t->engine_power,
            'vin' => $t->vin,
            'ts_mfr' => $t->ts_mfr,
            'pts_date' => $this->dateFormatter($t->pts_date),
            'pts_series_number' => $t->pts_series_number,
            'pts_issued_by' => $t->pts_issued_by,
            'pts_issued_address' => $t->pts_issued_address,
            'sts_date' => $this->dateFormatter($t->sts_date),
        ];
    }

    public function includeDocuments(Movable $t): Collection
    {
        return $this->collection($t->documents()->get(), new FileTransformer);
    }

    public function includeImages(Movable $t): Collection
    {
        return $this->collection($t->images()->get(), new FileTransformer);
    }

    public function includePtsScans(Movable $t): Collection
    {
        return $this->collection($t->pts_scans()->get(), new FileTransformer);
    }

    public function includeStsScans(Movable $t): Collection
    {
        return $this->collection($t->sts_scans()->get(), new FileTransformer);
    }
}
